package com.lovo.psc.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lovo.psc.entity.PscCommodity;
import com.lovo.psc.service.IPscCommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 刘子涵
 * @since 2022-07-07
 */
@RestController
@RequestMapping("/psc-commodity")
public class PscCommodityController {
    @Autowired
    IPscCommodityService service;

    @GetMapping("/findAll")
    public List<PscCommodity> findAll() {
        return service.list();
    }

    @GetMapping("/findByNum/{num}")
    public List<PscCommodity> findByNum(Integer num) {
        QueryWrapper<PscCommodity> qw = new QueryWrapper<>();
        return service.list(qw.eq("number", num));
    }

    @PostMapping("/del/{id}")
    public boolean del(@PathVariable("id") Integer id) {
        service.removeById(id);
        return true;
    }

    @PostMapping("/add")
    public boolean add(PscCommodity pscCommodity) {
        service.save(pscCommodity);
        return true;
    }

    @PostMapping("/update/{id}/{num}")
    public boolean update(@PathVariable("id") Integer id,
                          @PathVariable("num") Integer num) {
        PscCommodity obj = service.getById(id);
        obj.setEum(num);
        service.updateById(obj);
        return true;
    }
}
